$(function() {
	document.title = $.query.get('name') + ' - 修改 - 商家管理系统';

	var id = $.query.get('id');
	var name = $.query.get('name');
	var tel = $.query.get('tel');
	var type = $.query.get('type');
	var district = $.query.get('district');
	var address = $.query.get('address');
	var per = $.query.get('per');

	init();

	function init() {
		$('#id').val(id);
		$('#name').val(name);
		$('#tel').val(tel);
		$("[name='type'][value=" + type + "]").attr('checked', 'true');
		$("#district option[value='" + district + "']").attr("selected", true);
		$('#address').val(address);
		$('#per').val(per);
	}

	$('#resetBut').on('click', function() {
		init();
	})

	$('#subBut').on(
			'click',
			function() {
				var name_new = $('#name').val();
				var tel_new = $('#tel').val();
				var type_new = $('[name="type"]:checked').val();
				var district_new = $('#district').val();
				var address_new = $('#address').val();
				var per_new = $('#per').val();
				if (name_new == name && tel_new == tel && type_new == type
						&& district_new == district && address_new == address
						&& per_new == per) {
					alert("尚未修改任何数据");
					return;
				}
				if (sessionStorage.getItem('username') != null) {
					$('#updateForm').submit();
				} else {
					alert("你没有登录，请先登录。");
					window.location.href = "login.html";
				}
			})
})